package com.hht.toolanduilibs

import android.content.Context
import android.content.Intent


/**
 * Author:chen'hu
 * Time:2024/9/4 10:49
 * Description:This is DataExt
 */
/***
 * @param whiteBoardBean
 * @param annotationBean
 * */
data class ConfigurationBean(val whiteBoardBean: WhiteBoardBean, val annotationBean: AnnotationBean)

data class WhiteBoardBean(
    val corporationType: Int,// 0 鸿合，1 富创，2 朗国，3 Optoma
    val pkgName: String,//包名
    val className: String,//类名
    val isActivity: Boolean = true,
    val action: String? = "",//有些白板需要这个，有些不需要
    val putKey: String? = "",//有些白板需要这个，有些不需要
)

data class AnnotationBean(
    val corporationType: Int,// 0 鸿合，1 富创，2 朗国，3 Optoma
    val pkgName: String,//包名
    val className: String,//类名
    val isActivity: Boolean = false,
    val action: String? = "",//有些白板需要这个，有些不需要
    val putKey: String? = "",//有些白板需要这个，有些不需要
)

object CorporationType {
    const val HHT = 0
    const val IST = 1
    const val LG = 2
    const val OPTOMA = 3
}


fun Context.startActivityExt(block: Intent.() -> Unit): Boolean {
    var isOpen = true
    try {
        val intent = Intent()
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        intent.block()
        startActivity(intent)
    } catch (e: Exception) {
        isOpen = false
        e.printStackTrace()
    }
    return isOpen
}

fun Context.startServiceExt(block: Intent.() -> Unit): Boolean {
    var isOpen = true
    try {
        val intent = Intent()
        intent.block()
        startService(intent)
    } catch (e: Exception) {
        isOpen = false
        e.printStackTrace()
    }
    return isOpen
}

fun Context.sendBroadCastExt(block: Intent.() -> Unit): Boolean {
    var isOpen = true
    try {
        val intent = Intent()
        intent.block()
        sendBroadcast(intent)
    } catch (e: Exception) {
        isOpen = false
        e.printStackTrace()
    }
    return isOpen

}